package lab.anoper.juc.automatic;


import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author 闫家洪（yanjiahong@vcredit.com）
 * @since 2024/12/12
 */
public class AtomicIntegerDemo {
    //    static int currentThreads = 0;
    static MyAtomicInteger2 atomicInteger = new MyAtomicInteger2(0);

    public static void main(String[] args) throws Exception {
        AtomicInteger atomicInteger = new AtomicInteger(0);
//        atomicInteger.set();
//        atomicInteger.incrementAndGet();
        for (int i = 0; i < 10000; i++) {
            new Thread(() -> {
                int count = atomicInteger.incrementAndGet();
                System.out.println(Thread.currentThread().getName() + " " + count);
            }).start();
        }

        // 等待一段时间，确保所有线程都能完成
        Thread.sleep(3000);
        System.out.println("Final count: " + atomicInteger.get());
    }

}
